﻿package com.game.module.heroBuff.vo
{
	import com.dusk.tool.DataBase;
	import com.dusk.util.ResUtil;
	import com.game.data.constant.ConfigConst;
	
	import config.Config;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class SingleSavedBuff extends Sprite
	{
		
		public static var BUFF_DROPRATE_ADD:uint = 0;
		public static var BUFF_EXP_ADD:uint = 1;
		public static var BUFF_CRIT_ADD:uint = 2;
		public static var BUFF_ATK_ADD:uint = 3;
		public static var BUFF_HP_CURE:uint = 4;
		public static var BUFF_HP_ADD_28_BUFF:uint = 5;
		public static var BUFF_DEF_ADD_28_BUFF:uint = 6;
		public static var BUFF_ALLIANCE_ATK:uint = 7;
		public static var BUFF_MID_BUFF:uint = 8;
		
		public function SingleSavedBuff(param1:uint, value:int, time:int, idx:uint)
		{
			super();
			gc = Config.getIns();
			this.anti._type = param1;
			this.anti._value = value;
			this._time = time;
			this.anti._idx = idx;
			try
			{
				this.imgBm = (ResUtil.getImageBitmap("SAVEBUFF_" + param1) as Bitmap);
				this.addChild(this.imgBm);
				this.timeTf = new TextField();
				this.timeTtf = new TextFormat();
				this.timeTtf.font = ConfigConst.GAME_CONFIG_FONT;
				this.timeTtf.size = 18;
				this.timeTf.width = 120;
				this.timeTf.height = 30;
				this.timeTf.x = 40;
				this.timeTf.embedFonts = true;
				this.timeTf.defaultTextFormat = this.timeTtf;
				this.timeTf.selectable = false;
				this.addChild(this.timeTf);
			} catch (e:Error)
			{
				throw new Error("全局buff图标有误-->类型：" + param1);
			}
		}
		
		public var isDestroyed:Boolean = false;
		private var imgBm:Bitmap;
		private var timeTf:TextField;
		private var timeTtf:TextFormat;
		private var gc:Config;
		private var anti:DataBase = new DataBase();
		
		private var _time:int;
		
		public function get time():int
		{
			return this._time;
		}
		
		public function set time(value:int):void
		{
			this._time = value;
		}
		
		public function get idx():uint
		{
			return this.anti._idx;
		}
		
		public function set idx(value:uint):void
		{
			this.anti._idx = value;
		}
		
		public function get value():int
		{
			return this.anti._value;
		}
		
		public function set value(value:int):void
		{
			this.anti._value = value;
		}
		
		public function get type():uint
		{
			return this.anti._type;
		}
		
		public function set type(value:uint):void
		{
			this.anti._type = value;
		}
		
		public function step():void
		{
			this.y = 30 * this.anti._idx;
			this.display();
			if (this._time > 0)
			{
				this._time--;
				if (this._time == 0)
				{
					this.destroy();
				}
			}
		}
		
		public function destroy():void
		{
			this.isDestroyed = true;
			if (this.parent)
			{
				this.parent.removeChild(this);
			}
			if (this.imgBm)
			{
				this.imgBm.bitmapData.dispose();
			}
			this.imgBm = null;
		}
		
		private function display():void
		{
			var second:uint;
			var hour:uint;
			var min:uint;
			var sec:uint;
			if (this.timeTf)
			{
				second = this.time / gc.frameClips;
				hour = second / 3600;
				min = (second - (hour * 3600)) / 60;
				sec = second - hour * 3600 - min * 60;
				this.timeTf.text = ((hour > 0) ? (hour + ":") : "") + min + ":" + sec;
			}
			if (this.type == SingleSavedBuff.BUFF_DROPRATE_ADD)
			{
				this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "%)");
			}
			else
			{
				if (this.type == SingleSavedBuff.BUFF_EXP_ADD)
				{
					this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "倍)");
				}
				else
				{
					if (this.type == SingleSavedBuff.BUFF_CRIT_ADD)
					{
						this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "%)");
					}
					else
					{
						if (this.type == SingleSavedBuff.BUFF_ATK_ADD)
						{
							this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "点)");
						}
						else
						{
							if (this.type == SingleSavedBuff.BUFF_HP_CURE)
							{
								this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "点)");
							}
							else
							{
								if (this.type == SingleSavedBuff.BUFF_HP_ADD_28_BUFF)
								{
									this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "点)");
								}
								else
								{
									if (this.type == SingleSavedBuff.BUFF_DEF_ADD_28_BUFF)
									{
										this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "点)");
									}
									else
									{
										if (this.type == SingleSavedBuff.BUFF_ALLIANCE_ATK)
										{
											this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "点)");
										}
										else
										{
											if (this.type == SingleSavedBuff.BUFF_MID_BUFF)
											{
												this.timeTf.text = this.timeTf.text + (("(" + this.anti._value) + "点)");
											}
										}
									}
								}
							}
						}
					}
				}
			}
			this.timeTf.width = this.timeTf.textWidth + 10;
		}
	}
}

